Write-Host "=== 测试修复结果 ===" -ForegroundColor Green

Write-Host "`n1. 检查迁移状态..." -ForegroundColor Yellow
try {
    dotnet ef migrations list -p BackOffice.Infrastructure -s BackOffice.Api
    Write-Host "✓ 迁移状态检查完成" -ForegroundColor Green
} catch {
    Write-Host "✗ 迁移状态检查失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n2. 测试登录功能..." -ForegroundColor Yellow
try {
    $loginData = @{
        username = "admin"
        password = "password"
    } | ConvertTo-Json
    
    $loginResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/auth/login" -Method POST -Body $loginData -ContentType "application/json"
    
    if ($loginResponse.token) {
        Write-Host "✓ 登录成功，获取到Token" -ForegroundColor Green
        $token = $loginResponse.token
        
        Write-Host "`n3. 测试API功能..." -ForegroundColor Yellow
        
        $headers = @{
            "Authorization" = "Bearer $token"
            "Content-Type" = "application/json"
        }
        
        # 测试角色列表
        try {
            $roleResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/role/list" -Method GET -Headers $headers
            Write-Host "✓ 角色列表API正常，返回 $($roleResponse.Count) 条记录" -ForegroundColor Green
        } catch {
            Write-Host "✗ 角色列表API失败: $($_.Exception.Message)" -ForegroundColor Red
        }
        
        # 测试权限列表
        try {
            $permissionResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/permission/list" -Method GET -Headers $headers
            Write-Host "✓ 权限列表API正常，返回 $($permissionResponse.Count) 条记录" -ForegroundColor Green
        } catch {
            Write-Host "✗ 权限列表API失败: $($_.Exception.Message)" -ForegroundColor Red
        }
        
        # 测试文章列表
        try {
            $articleResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/article/list" -Method GET -Headers $headers
            Write-Host "✓ 文章列表API正常，返回 $($articleResponse.Count) 条记录" -ForegroundColor Green
        } catch {
            Write-Host "✗ 文章列表API失败: $($_.Exception.Message)" -ForegroundColor Red
        }
        
    } else {
        Write-Host "✗ 登录失败，未获取到Token" -ForegroundColor Red
    }
} catch {
    Write-Host "✗ 登录失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n=== 测试完成 ===" -ForegroundColor Green 